import Vue from "vue";
import VueRouter from "vue-router";
import Default from "../Default.vue";
import Home from "../views/Home.vue";
const Login = ()=> import( "../views/Login.vue");
const Welcome = ()=> import( "../components/Welcome.vue");
const Detail = ()=> import( "../components/public/Detail");
const Users = ()=> import( "../components/User/Users.vue");
const Authority = ()=> import( "../components/auth/Authority.vue");
const Rolhouduanes = ()=> import( "../components/auth/Roles.vue");
const TaskManage = ()=> import( "../components/task/TaskManage.vue");
const TSKSettlement = ()=> import( "../components/task/TSKSettlement.vue");
const TSKSettlementDetail = ()=> import( "../components/task/TSKSettlementDetail.vue");
const TaskInfo = ()=> import( "../components/task/TaskInfo.vue");
const TaskDetail = ()=> import( "../components/task/TaskDetail.vue");
const Error404 = ()=> import( "../components/404.vue");
const Report = ()=> import( "../components/report/Report.vue");
const Charge = ()=> import( "../components/report/Charge.vue");
const WorkStatistics = ()=> import( "../components/report/WorkStatistics.vue");
const MonthStatistics = ()=> import( "../components/report/MonthStatistics.vue");
const Profitstatement = ()=> import( "../components/report/Profitstatement.vue");
const Marketing = ()=> import( "../components/marketing/Marketing.vue");
const Management = ()=> import( "../components/management/Management.vue");
const MerchantList = ()=> import( "../components/merchant/MerchantList");
const AddMerchant = ()=> import( "../components/merchant/AddMerchant");
const EditMerchant = ()=> import( "../components/merchant/EditMerchant");
const CheckMerchant = ()=> import( "../components/merchant/CheckMerchant");
const AddMerchant2 = ()=> import( "../components/merchant/AddMerchant2");
const RegisterPhone = ()=> import( "../components/merchant/RegisterPhone");
const BusinessInfo = ()=> import( "../components/merchant/BusinessInfo");
const SelectType = ()=> import( "../components/merchant/SelectType");
const MerchantInfo = ()=> import( "../components/merchant/MerchantInfo");
const MerchantSign = ()=> import( "../components/merchant/MerchantSign");
const MerchantContract = ()=> import( "../components/merchant/MerchantContract");
const MerchantCheck = ()=> import( "../components/merchant/MerchantCheck");
const Employee = ()=> import( "../components/employee/Employee.vue");
const EmployeeSign = ()=> import( "../components/employee/EmployeeSign.vue");
const EmployeeCredit = ()=> import( "../components/employee/EmployeeCredit.vue");
const Account = ()=> import( "../components/account/Account.vue");
const Recharge = ()=> import( "../components/account/Recharge.vue");
const PayDetail = ()=> import( "../components/account/PayDetail.vue");
const Payroll = ()=> import( "../components/account/Payroll.vue");
const Payapply = ()=> import( "../components/account/Payapply.vue");
const PayrollDetails = ()=> import( "../components/account/PayrollDetails.vue");
const Refund = ()=> import( "../components/account/Refund.vue");
const PayRefund = ()=> import( "../components/account/PayRefund.vue");
const PayGuide = () => import("../components/account/PayGuide.vue");
const AccountBook = () => import("../components/alipay/AccountBook.vue");
const WagesPay = ()=> import( "../components/wagespay/WagesPay.vue");
const WagesPayBill = ()=> import( "../components/wagespay/WagesPayBill.vue");
const Balance = ()=> import( "../components/report/Balance");
const Invoice = ()=> import( "../components/invoice/Invoice.vue");
const InvoiceRecordEdit = ()=> import( "../components/invoice/InvoiceRecordEdit.vue");
const InvoiceInfo = ()=> import( "../components/invoice/InvoiceInfo.vue");
const SubmitSuccessfully = ()=> import( "../components/invoice/SubmitSuccessfully.vue");
const Apply = ()=> import( "../components/invoice/Apply.vue");
const EditInvoice = ()=> import( "../components/invoice/EditInvoice.vue");
const EditInvoices = ()=> import( "../components/invoice/EditInvoices.vue");
const InvoiceChecks = ()=> import( "../components/invoice/InvoiceChecks.vue");
const InvoiceRecord = ()=> import( "../components/invoice/InvoiceRecord.vue");
const InvoiceAddress = ()=> import( "../components/invoice/InvoiceAddress.vue");
const Password = ()=> import( "../components/setting/Password.vue");
const AccountBalance = ()=> import( "../components/setting/AccountBalance.vue");
const ManagerList = ()=> import( "../components/setting/ManagerList.vue");
const ManagerRole = ()=> import( "../components/setting/ManagerRole.vue");
const Menus = ()=> import( "../components/setting/Menus");
const Logs = ()=> import( "../components/setting/Logs");
const SysConfig = ()=> import( "../components/setting/SysConfig");
const EditRole = ()=> import( "../components/setting/EditRole");
const EditRoleAuth = ()=> import( "../components/setting/EditRoleAuth");
const Sign = ()=> import( "../views/Sign.vue");
const BrandManagement = ()=> import( "../components/channel/BrandManagement");
const ServiceProviderInf = ()=> import( "../components/channel/ServiceProviderInf");
const RM_EmpList = ()=> import( "../components/systemSet/RM_EmpList");
const TradeSet = ()=> import( "../components/systemSet/TradeSet");
const SignSet = ()=> import( "../components/systemSet/SignSet");
const SmsChannelSet = ()=> import( "../components/systemSet/SmsChannelSet");
const Agent = ()=> import( "../components/channel/Agent");
const AgentContract = ()=> import( "../components/channel/AgentContract");
const Notification = ()=> import( "../components/notification/Notification");
const DictionaryTypes = ()=> import( "../components/maintenance/DictionaryTypes");
const DictionaryValues = ()=> import( "../components/maintenance/DictionaryValues");
const SmsMode = ()=> import( "../components/maintenance/SmsMode");
const TaxInf = ()=> import( "../components/maintenance/TaxInf");
const ContentTemplate = ()=> import( "../components/maintenance/ContentTemplate");
const PayChannel = ()=> import( "../components/maintenance/PayChannel");
const VerifyBankCard = ()=> import( "../components/operations/VerifyBankCard");
const SMSInfList = ()=> import( "../components/operations/SMSInfList");
const EmpAudit = ()=> import( "../components/operations/EmpAudit");
const DataTemplate = () => import("../components/operations/DataTemplate");
const test1 = () => import("../components/task/test1.vue");
const originalPush = VueRouter.prototype.push;

// VueRouter.prototype.push = function push(location) {
//   let url = window.location.href.match(/.+(\/\w+)$/);
//   console.log(url);
//   console.log(location);
//   if (location == url[1]) {
//     return;
//   }
//   return originalPush.call(this, location);
// };

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  {
    path: "*",
    component: Error404,

    // redirect: "home/*",
  },
  {
    path: "/login",
    name: "Login",
    component: Login,
  },
  {
    path: "/sign",
    name: "Sign",
    component: Sign,
  },
  {
    path: "/home",
    component: Home,
    redirect: "/welcome",
    children: [
      {
        path: "/welcome",
        name: "欢迎",
        component: Welcome,
      },
      {
        path: "*",
        name: "错误",
        component: Error404,
      },
      {
        path: "/detail",
        name: "详情",
        component: Detail,
      },
      {
        path: "/ServiceProjectList",
        name: "任务管理",
        component: Default,
        redirect: "/ServiceProjectList/",
        children: [
          {
            path: "/test1",
            name: "测试页",
            component: test1,
          },
          {
            path: "/",
            name: "任务列表",
            component: TaskManage,
          },
          {
            path: "TSKSettlementDetail",
            name: "任务结算详情",
            component: TSKSettlementDetail,
          },
        ],
      },
      {
        path: "/TSKSettlement",
        name: "结算列表",
        component: TSKSettlement,
      },

      {
        path: "/task-info",
        name: "任务信息",
        component: TaskInfo,
      },
      {
        path: "/task-detail",
        name: "任务详情",
        component: TaskDetail,
      },
      {
        path: "/users",
        name: "用户列表",
        component: Users,
      },
      {
        path: "/authority",
        name: "权限列表",
        component: Authority,
      },
      {
        path: "/roles",
        name: "角色列表",
        component: Rolhouduanes,
      },
      {
        path: "/merchantlist",
        name: "客户管理",
        component: Default,
        redirect: "/merchantlist/",
        children: [
          {
            path: "/",
            name: "客户列表",
            component: MerchantList,
          },
          {
            path: "add-merchant",
            name: "添加客户",
            component: AddMerchant,
            redirect: "/merchantlist/add-merchant/register-phone",
            children: [
              {
                path: "register-phone",
                name: "客户手机注册",
                component: RegisterPhone,
              },
              {
                path: "select-type",
                name: "选择类型",
                component: SelectType,
              },
              {
                path: "business-info",
                name: "信息登记",
                component: BusinessInfo,
              },
              {
                path: "merchant-info",
                name: "客户信息2",
                component: MerchantInfo,
              },
            ],
          },
          {
            path: "add-merchant2",
            name: "客户信息",
            component: AddMerchant2,
          },
          {
            path: "edit-merchant",
            name: "修改客户信息",
            component: EditMerchant,
          },
        ],
      },
      {
        path: "/servicesignlist",
        name: "客户签约",
        component: Default,
        redirect: "/servicesignlist/",
        children: [
          {
            path: "/",
            name: "客户签约列表",
            component: MerchantSign,
          },
          {
            path: "/merchant-contract",
            name: "客户合同列表",
            component: MerchantContract,
          },
        ],
      },

      {
        path: "/merchantchecklist",
        name: "客户审核列表",
        component: MerchantCheck,
      },
      {
        path: "/check-merchant",
        name: "客户审核",
        component: CheckMerchant,
      },
      {
        path: "/employeeList",
        name: "灵工列表",
        component: Employee,
      },
      {
        path: "/employeeSignList",
        name: "灵工签约列表",
        component: EmployeeSign,
      },
      {
        path: "/PersonalCreditList",
        name: "授信灵工列表",
        component: EmployeeCredit,
      },
      {
        path: "/accountinfo",
        name: "我的账户",
        component: Account,
        children: [
          {
            path: "rights",
            name: "我的权益",
            component: Recharge,
          },
        ],
      },

      {
        path: "/recharge",
        name: "充值管理",
        component: Recharge,
      },
      {
        path: "/pay-detail",
        name: "立即充值",
        component: PayDetail,
      },
      {
        path: "/apply",
        name: "代发申请",
        component: Payapply,
      },
      {
        path: "/review",
        name: "资金代发",
        component: Payroll,
      },
      {
        path: "/review-details",
        name: "资金代发明细",
        component: PayrollDetails,
      },
      {
        path: "/refund",
        name: "退款申请",
        component: Refund,
      },
      {
        path: "/guide",
        name: "充值指引",
        component: PayGuide,
      },
      {
        path: "/payrefund",
        name: "代发退款",
        component: PayRefund,
      },
      {
        path: "/query",
        name: "代发明细",
        component: WagesPay,
      },
      {
        path: "/batchlist",
        name: "代发账单",
        component: WagesPayBill,
      },
      {
        path: "/guide1",
        name: "退款明细",
        component: WagesPayBill,
      },
      {
        path: "/balance",
        name: "客户余额",
        component: Balance,
      },
      {
        path: "/charge",
        name: "充值记录",
        component: Charge,
      },
      {
        path: "/alipayBook",
        name: "记账本",
        component: AccountBook,
      },
      {
        path: "/statements",
        name: "代发报表",
        component: Report,
      },
      {
        path: "/settleAccounts",
        name: "分润报表",
        component: Report,
      },
      {
        path: "/WorkStatistics",
        name: "工作统计",
        component: WorkStatistics,
      },
      {
        path: "/MerchantMonthStatistics",
        name: "交易明细",
        component: MonthStatistics,
      },
      {
        path: "/Profitstatement",
        name: "佣金明细",
        component: Profitstatement,
      },
      {
        path: "/marketing",
        name: "当前任务",
        component: Marketing,
      },
      { path: "/management", component: Management },

      {
        path: "/invoiceApplyList",
        name: "发票申请",
        component: Invoice,
        redirect: "/invoiceApplyList",
        children: [
          {
            path: "/",
            name: "勾选订单",
            component: Apply,
          },
          {
            path: "edit-invoice",
            name: "开票申请",
            component: EditInvoice,
          },
          {
            path: "edit-invoices",
            name: "发票填写",
            component: EditInvoices,
          },
          {
            path: "invoice-info",
            name: "发票信息",
            component: InvoiceInfo,
          },
          {
            path: "successfully",
            name: "提交成功",
            component: SubmitSuccessfully,
          },
        ],
      },
      {
        path: "/invoice_checklist",
        name: "开票审核",
        component: InvoiceChecks,
      },
      {
        path: "/invoice_list",
        name: "开票记录",
        component: InvoiceRecord,
      },
      {
        path: "/invoice_edit",
        name: "补充开票信息",
        component: InvoiceRecordEdit,
      },
      {
        path: "/invoice_address",
        name: "开票指引",
        component: InvoiceAddress,
      },

      {
        path: "/agentwebconfig",
        name: "品牌管理",
        component: BrandManagement,
      },
      {
        path: "/agentlist",
        name: "代理商信息",
        component: Agent,
      },
      {
        path: "/agent-contract",
        name: "代理商合同",
        component: AgentContract,
      },
      {
        path: "/servicelist",
        name: "服务商信息",
        component: ServiceProviderInf,
      },
      {
        path: "/RM_EmpList",
        name: "收单授权",
        component: RM_EmpList,
      },

      {
        path: "/systemSet",
        name: "交易控制",
        component: TradeSet,
      },
      {
        path: "/SignSet",
        name: "签约控制",
        component: SignSet,
      },

      {
        path: "/set_pwd",
        name: "密码管理",
        component: Password,
      },

      {
        path: "/AccountBalance",
        name: "余额信息",
        component: AccountBalance,
      },

      {
        path: "/sys_config",
        name: "系统设置",
        component: SysConfig,
      },
      {
        path: "/manager_list",
        name: "账号管理",
        component: ManagerList,
      },
      {
        path: "/manager_role",
        name: "角色管理",
        component: ManagerRole,
      },
      {
        path: "/edit_role",
        name: "修改角色",
        component: EditRole,
      },
      {
        path: "/edit_roleAuth",
        name: "修改角色权限",
        component: EditRoleAuth,
      },
      {
        path: "/sys_navigation",
        name: "菜单管理",
        component: Menus,
      },
      {
        path: "/manager_log",
        name: "管理日志",
        component: Logs,
      },
      {
        path: "/dictionary_types_list",
        name: "字典类别",
        component: DictionaryTypes,
      },
      {
        path: "/dictionary_values_list",
        name: "字典管理",
        component: DictionaryValues,
      },
      {
        path: "/SmsModel",
        name: "短信模板",
        component: SmsMode,
      },
      {
        path: "/ContentTemplate",
        name: "内容模板",
        component: ContentTemplate,
      },
      {
        path: "/taxinflist",
        name: "税务机构",
        component: TaxInf,
      },
      {
        path: "/SmsChannelSet",
        name: "辅助工具",
        component: SmsChannelSet,
      },
      {
        path: "/DataBaseSet",
        name: "数据库备份",
        component: Error404,
      },
      {
        path: "/miniappsSet",
        name: "小程序设置",
        component: Error404,
      },
      {
        path: "/bankcodeList",
        name: "代付通道",
        component: PayChannel,
      },
      {
        path: "/verifybankcard",
        name: "认证信息",
        component: VerifyBankCard,
      },
      {
        path: "/DataTemplate",
        name: "数据模板",
        component: DataTemplate,
      },
      {
        path: "/smsInfList",
        name: "短信日志",
        component: SMSInfList,
      },
      {
        path: "/11",
        name: "常用工具",
        component: EmpAudit,
      },
      // {
      //   path: "/statementList",
      //   name: "结算列表",
      //   component: Error404,
      // },
      {
        path: "/sys_notice",
        name: "系统通知",
        component: Notification,
      },
      {
        path: "/pabankinterfacecfg",
        name: "平安接口参数",
        component: Password,
      },
    ],
  },
];

const router = new VueRouter({
  // mode: "history",
  base: process.env.BASE_URL,
  routes,
});
// Add Access Control

router.beforeEach((to, from, next) => {
  if (to.path === from.path) {
    console.log(to.path);
    console.log(from.path);
    return;
  }
  // return next();

  if (to.path === "/login") {
    return next();
  }

  const tokenStr = window.sessionStorage.getItem("roletype");
  if (!tokenStr) {
    return next("/login");
  }
  const musteditpwd = window.sessionStorage.getItem("musteditpwd");
  if (musteditpwd == "1") {
    console.log(musteditpwd);
    // this.$notify({
    //   title: "警告",
    //   message: "请修改您的初始密码！",
    //   type: "warning",
    //   duration: 0,
    // });
    // this.$router.push("/set_pwd");

    return to.path === "/set_pwd" ? next() : next("/set_pwd");
  }
  return next();
});

export default router;
